﻿var flag = "";
//初始化
if (typeof ($) != "undefined") {
    $(document).ready(function () {
        //alert("TaskTypeID:" + getPar1("TaskTypeID"))
        flag = getPar1("flag");
        var TaskTypeID = getPar1("TaskTypeID");
        var TaskTypeName = getPar1("TaskTypeName");
        //debugger;
        if (flag == "Add") {
            $("#ParentID").val(TaskTypeID)
            $("#ParentCategory").val(TaskTypeName);
            GetParentCategory(TaskTypeID);
        }
        else if (flag == "Edit") {
            $("#TaskType").val(TaskTypeName);
            GetCategory(TaskTypeID);
        }
        //获取提报人employeeId
        YAHOO.util.Connect.asyncRequest('POST', "../EHR/GetCurrentUser.aspx", {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str != "-1") {
                        var token = str.split('_');
                        instance[0].ModifyUser = token[0];
                    }
                }
                catch (e) {
                }
                finally {

                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);

    });
    instance[0].ModifyTime = new Date();
}

//获取上级分类信息
function GetParentCategory(ParentID) {
    //alert("ParentID:" + ParentID);
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=SysTaskType&condition=ID='" + ParentID + "'";
    $.get(url, function (d, s) {
        //debugger;
        var list = eval("(" + d + ")");
        for (var o in list.rows) {
            //debugger;
            var t = list.rows[o].Seq;
            if (typeof (t) != "undefined") {
                if (flag == "Add") {
                    //$("#Seq").val(t + "-");
                    GetChildNextSeq(ParentID);
                }
                else if (flag == "Edit") {
                    $("#ParentCategory").val(list.rows[o].Category);
                }
            }
        }
    });
}

//自动生成下级分类编码
function GetChildNextSeq(ParentID) {
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/DatPostAjax.aspx?flag=getchildsystasktypenextseq" + "&ParentID=" + ParentID, {
        success: function (res) {
            //debugger;
            try {
                var str = res.responseText;
                $("#Seq").val(str);
            }
            catch (e) {
                alert("生成编码失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}



//获取自己信息
function GetCategory(ID) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=SysTaskType&condition=ID='" + ID + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        for (var o in list.rows) {
            //debugger;
            var t = list.rows[o].Seq;
            if (typeof (t) != "undefined") {
                $("#Seq").val(t);
                $("#Notes").val(list.rows[o].Notes);
                $("#ParentID").val(list.rows[o].ParentID);
                GetParentCategory(list.rows[o].ParentID);
            }
        }
    });
}

var fnCheckData = function () {
    try {
        if ($("#TaskType").val() == "") {
            return "【分类名称】不能为空!";
        }
        if ($("#ParentID").val() == "") {
            return "【上级分类】不能为空!";
        }
        if ($("#Seq").val() == "") {
            return "【层级编码】不能为空!";
        }
    }
    catch (e)
     { }
}
